import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/utils/mode_config.dart';
import 'package:ball_lion/routes/routes.dart';
import 'package:ball_lion/module/expert/items/expert_first_tag.dart';
import 'package:ball_lion/module/expert/items/expert_logo.dart';
import 'package:ball_lion/module/pick/items/expert_record_tag.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';

enum AvatarType {
  normal,
  tag,
  record;
}

class AvatarLabel extends StatelessWidget {
  final String? avatarUrl;
  final String? id;
  final String? name;
  final int? type;
  final String? index;
  final double avatarSize;
  final double nameSize;
  final FontWeight nameWeight;
  final Function? needJump;
  final bool? isInvite;
  final bool? inLive;
  final int? planCnt;
  final AvatarType avatarType;
  final List<String>? tagList;
  final String? firstTag;
  final String? secondTag;
  final String? content;
  final TextStyle? contentStyle;

  const AvatarLabel.tag(
      {super.key,
      required this.avatarUrl,
      required this.name,
      required this.tagList,
      required this.id,
      this.avatarSize = 40,
      this.type = 2,
      this.index,
      this.nameSize = 14,
      this.nameWeight = FontWeight.w400,
      this.needJump,
      this.isInvite,
      this.inLive,
      this.planCnt,
      this.avatarType = AvatarType.tag})
      : firstTag = null,
        secondTag = null,
        content = null,
        contentStyle = null;

  const AvatarLabel.record(
      {super.key,
      required this.avatarUrl,
      required this.name,
      this.firstTag,
      this.secondTag,
      required this.id,
      this.avatarSize = 40,
      this.type = 2,
      this.index,
      this.nameSize = 14,
      this.nameWeight = FontWeight.w400,
      this.needJump,
      this.isInvite,
      this.inLive,
      this.planCnt,
      this.avatarType = AvatarType.record})
      : tagList = null,
        content = null,
        contentStyle = null;

  const AvatarLabel.normal(
      {super.key,
      required this.avatarUrl,
      required this.name,
      this.content,
      this.contentStyle,
      required this.id,
      this.avatarSize = 40,
      this.type = 2,
      this.index,
      this.nameSize = 14,
      this.nameWeight = FontWeight.w400,
      this.needJump,
      this.isInvite,
      this.inLive,
      this.planCnt,
      this.avatarType = AvatarType.normal})
      : tagList = null,
        firstTag = null,
        secondTag = null;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (needJump == null) {
          Get.toNamed(Routes.userPage,
              arguments: id,
              parameters: {"type": "$type", "index": index ?? ""});
        } else {
          needJump?.call();
        }
      },
      child: Row(
        children: [
          ExpertLogo(
            logo: avatarUrl,
            hasAuth: isInvite,
            inLive: inLive,
            size: avatarSize,
            planCnt: planCnt,
          ),
          Container(width: 8),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Row(
                  children: [
                    QsText(name ?? "",
                        fontSize: nameSize,
                        color: Colours.text292D32,
                        fontWeight: nameWeight),
                    if (firstTag.hasValue) ...[
                      Container(width: 4),
                      ExpertFirstTag(tag: firstTag!)
                    ]
                  ],
                ),
                if (ModeConfig.expertRecord) ...[
                  Container(height: 2),
                  if (avatarType == AvatarType.tag)
                    Row(
                      children: List.generate(
                          tagList?.length ?? 0,
                          (index) => Container(
                                margin: const EdgeInsets.only(right: 4),
                                height: 15,
                                alignment: Alignment.center,
                                padding:
                                    const EdgeInsets.symmetric(horizontal: 4),
                                decoration: BoxDecoration(
                                    color: Colours.greyF2F3F7,
                                    borderRadius: BorderRadius.circular(4)),
                                child: QsText(tagList?[index] ?? "",
                                    fontSize: 10, color: Colours.grey66),
                              )),
                    )
                  else if (avatarType == AvatarType.record)
                    Row(children: [
                      if (secondTag != null)
                        ExpertRecordTag(type: 5, text: secondTag)
                    ])
                  else if (avatarType == AvatarType.normal)
                    QsText.style(content ?? "", style: contentStyle)
                ]
              ],
            ),
          )
        ],
      ),
    );
  }
}
